package com.example.glgk.service;

import com.example.glgk.dto.indicator.*;
import com.example.glgk.dto.indicatorAnalysisDto.DepartmentDto;
import com.example.glgk.entity.DepartmentIndicatorEntity;
import com.example.glgk.entity.ElementDataEntity;
import com.example.glgk.entity.IndicatorDataEntity;
import com.example.glgk.entity.indicator.RankEntity;
import com.example.glgk.mapper.DepCPMapper;
import com.example.glgk.mapper.indicator.DepartmentIndicatorMapper;
import com.example.glgk.mapper.indicator.IndicatorCalculateMapper;
import com.example.glgk.service.indicator.IndicatorCalculateService;
import com.example.glgk.utils.Calculator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author liuxingkun
 */
@Service
@Slf4j
public class DepartmentIndicatorService {

    @Autowired
    DepartmentIndicatorMapper departmentIndicatorMapper;

    @Autowired
    IndicatorCalculateService indicatorCalculateService;

    @Autowired
    IndicatorCalculateMapper indicatorCalculateMapper;

    @Autowired
    DepCPMapper depCPMapper;

    /**
     * 查询部门/科室所涉及指标
     *
     * @param indicatorCalculateDto
     * @return
     */
    public List<ResponsibleIndicator> getResponsibleIndicators(IndicatorCalculateDto indicatorCalculateDto) {
        if ("ZNBM".equals(indicatorCalculateDto.getUserInfo().getParentDepartmentId())) {
            log.info("当前部门是：{}", indicatorCalculateDto.getUserInfo().getWardName());
            return departmentIndicatorMapper.getResponsibleIndicators(indicatorCalculateDto);
        } else {
            //return departmentIndicatorMapper.getDeptIndicator(indicatorCalculateDto);
            return departmentIndicatorMapper.getDeptResponsibleIndicator(indicatorCalculateDto);
        }
    }

    public List<DataListDto> getDataList(IndicatorCalculateDto indicatorCalculateDto) {
        Map<String, List<IndicatorOverviewDto>> overviewData = indicatorCalculateService.getOverviewData(indicatorCalculateDto);
        String key = indicatorCalculateDto.getFlag() == 0 ? "full" : indicatorCalculateDto.getFlag() == 1 ? "up" : indicatorCalculateDto.getFlag() == 2 ? "level" : "down";
        if (CollectionUtils.isEmpty(overviewData.get(key))) {
            return null;
        }
        List<DataListDto> result = new ArrayList<>();
        List<String> ids = overviewData.get(key).stream().map(IndicatorOverviewDto::getId).filter(StringUtils::isNotBlank).collect(Collectors.toList());
        indicatorCalculateDto.setIndicatorIds(ids);
        setYears(indicatorCalculateDto);
        /*
         *todo 获得当前科室所属临床科室和非临床科室
         * 然后查询临床科室或者非临床科室的负责的各项指标的排名
         *  */
        //是否临床科室
        String isClinical = depCPMapper.queryIsClinical(indicatorCalculateDto.getUserInfo().getWardName());

        List<RankEntity> ranks = departmentIndicatorMapper.queryRank(indicatorCalculateDto, isClinical);
        Map<String, List<RankEntity>> rankMap = ranks.stream().collect(Collectors.groupingBy(RankEntity::getIndicator));
        //近五年数据
        List<OverDataDto> overDataDtos = departmentIndicatorMapper.getOverDataDtos(indicatorCalculateDto);
        Map<String, List<OverDataDto>> collect1 = overDataDtos.stream().collect(Collectors.groupingBy(OverDataDto::getId));
        //三年同时间段的数据
        List<IndicatorOverviewDto> dataList = indicatorCalculateMapper.getDataList(indicatorCalculateDto);
        Map<String, List<IndicatorOverviewDto>> collect2 = dataList.stream().collect(Collectors.groupingBy(IndicatorOverviewDto::getId));
        for (String id : ids) {
            if (!collect1.containsKey(id) && !collect2.containsKey(id)) {
                return null;
            }
            String name = collect1.containsKey(id) ? collect1.get(id).get(0).getIndicator() : collect2.get(id).get(0).getIndicatorName();
            DataListDto dataListDto = DataListDto.builder()
                    .indicatorName(name)
                    .dataDetails(new DataDetail())
                    .build();
            if (CollectionUtils.isNotEmpty(rankMap.get(name))) {
                dataListDto.setRank(rankMap.get(name).get(0).getRank());
            }
            DataDetail dataDetail = new DataDetail();
            dataDetail.setDeptList1(collect1.get(id));
            List<AnnexDataDto> deptList2 = new ArrayList<>();
            List<IndicatorOverviewDto> indicatorOverviewDtos = collect2.get(id);
            if (CollectionUtils.isNotEmpty(indicatorOverviewDtos)) {
                IndicatorOverviewDto indicatorOverviewDto = indicatorOverviewDtos.get(0);
                AnnexDataDto annexDataDto = AnnexDataDto.builder().indicatorXh(indicatorOverviewDto.getIndicatorXh())
                        .indicatorName(indicatorOverviewDto.getIndicatorName())
                        .indicatorUnit(indicatorOverviewDto.getUnit())
                        .responsibleDepartment(indicatorOverviewDto.getResponsibleDepartment())
                        .leader(indicatorOverviewDto.getLeader())
                        .annexYearDtos(new ArrayList<>())
                        .deptName(indicatorOverviewDto.getDeptName())
                        .build();
                //组装多级表头数据
                for (IndicatorOverviewDto dto : indicatorOverviewDtos) {
                    AnnexYearDto annexYearDto = AnnexYearDto.builder().time(dto.getTime()).indicatorValue(dto.getIndicatorValue()).fullValue(dto.getFullValue()).yoyValue(dto.getYoyValue()).momValue(dto.getMomValue()).build();
                    annexDataDto.getAnnexYearDtos().add(annexYearDto);
                }
                deptList2.add(annexDataDto);
            }
            dataDetail.setDeptList2(deptList2);
            dataListDto.setDataDetails(dataDetail);
            result.add(dataListDto);
        }
        return result;
    }

    /**
     * 设置近五年的年份
     *
     * @param indicatorCalculateDto
     */
    private void setYears(IndicatorCalculateDto indicatorCalculateDto) {
        SimpleDateFormat sdf;
        if (indicatorCalculateDto.getTimeNode().equals("month")) {
            sdf = new SimpleDateFormat("yyyy-MM");
        } else {
            sdf = new SimpleDateFormat("yyyy");
        }

        String startTime = indicatorCalculateDto.getStartTime();
        Date date = null;
        try {
            date = sdf.parse(startTime);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int startYear = cal.get(Calendar.YEAR);
        int previousYear = startYear - 1;
        int twoYearsAgoYear = startYear - 2;
        int threeYearsAgoYear = startYear - 3;
        int fourYearsAgoYear = startYear - 4;
        List<Integer> years = Arrays.asList(startYear, previousYear, twoYearsAgoYear, threeYearsAgoYear, fourYearsAgoYear);
        indicatorCalculateDto.setYears(years);
    }


    /**
     * 设置近五年的年份
     *
     * @param indicatorCalculateDto
     */
    private void setLastFiveYears(IndicatorCalculateDto indicatorCalculateDto) {
        List<String> fiveYears = new ArrayList<>();
        Year year = Year.now();
        fiveYears.add(year.toString());
        fiveYears.add(year.minusYears(1).toString());
        fiveYears.add(year.minusYears(2).toString());
        fiveYears.add(year.minusYears(3).toString());
        fiveYears.add(year.minusYears(4).toString());
        indicatorCalculateDto.setLastFiveYears(fiveYears);
    }


    public List<DataListDto> getMonitorIndicatorDataList(IndicatorCalculateDto indicatorCalculateDto) {

        List<DataListDto> dataListDtoList = new ArrayList<>();
        List<String> times = indicatorCalculateDto.getTimes();
        if (times.size() == 0) {
            return null;
        }
        List<String> yoyTimes = getYoyTime(times);
        List<String> beforeYoyTimes = getYoyTime(yoyTimes);
        List<String> previousYoyTimes = getYoyTime(beforeYoyTimes);

        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));

        Map<String, List<IndicatorOverviewDto>> overviewData = indicatorCalculateService.getMonitorIndicatorOverviewData(indicatorCalculateDto);
        //flag   0:满分  1:进步  其它:退步
        String key = indicatorCalculateDto.getFlag() == 0 ? "full" : indicatorCalculateDto.getFlag() == 1 ? "up" : "down";
        if (CollectionUtils.isEmpty(overviewData.get(key))) {
            return null;
        }
        // 查出所有手填指标的 id
        List<ElementDataEntity> elementDataEntities = indicatorCalculateMapper.getDeptElement();
        //将id全部抽取出来
        List<String> handFillIds = elementDataEntities.stream().map(e -> e.getId()).collect(Collectors.toList());

        List<IndicatorOverviewDto> deptIndicatorList = new ArrayList<>();
        // 确定当前指标是否是科室层面的指标  只有科室层面的指标才有必要查科室数据
        List<IndicatorOverviewDto> indicatorOverviewDtos = overviewData.get(key);

        for (IndicatorOverviewDto indicatorOverviewDto : indicatorOverviewDtos) {
            if (org.springframework.util.StringUtils.isEmpty(indicatorOverviewDto.getIds())) {
                continue;
            }
            String[] ids = indicatorOverviewDto.getIds().split(",");
            List<String> idList = Arrays.asList(ids);
            if (handFillIds.containsAll(idList)) {
                //说明是科室指标
                deptIndicatorList.add(indicatorOverviewDto);
            }
        }


        //  以下部分用来查询诊疗组信息
        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));

        // 根据所有父指标的index_code拿到其对应所有子指标
        List<String> indexCodeList = indicatorOverviewDtos.stream().map(e -> e.getIndexCode()).collect(Collectors.toList());
        indicatorCalculateDto.setIndexCodeList(indexCodeList);
        List<IndicatorDataEntity> relationIndicators = departmentIndicatorMapper.getRelationIndicators(indicatorCalculateDto);

        // 查出每个诊疗组的数据
        List<DepartmentIndicatorEntity> curDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);

        indicatorCalculateDto.setStartTime(yoyTimes.get(0));
        indicatorCalculateDto.setEndTime(yoyTimes.get(yoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> lastDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);

        indicatorCalculateDto.setStartTime(beforeYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(beforeYoyTimes.get(beforeYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> beforeDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);

        indicatorCalculateDto.setStartTime(previousYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(previousYoyTimes.get(previousYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> previousDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);




        Map<String, List<DepartmentIndicatorEntity>> curDrgMap = curDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> lastDrgMap = lastDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> beforeDrgMap = beforeDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> previousDrgMap = previousDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));

        setLastFiveYears(indicatorCalculateDto);
        List<DepartmentIndicatorEntity> lastFiveYearsDrgData = indicatorCalculateMapper.queryLastFiveYearsDrgData(indicatorCalculateDto);
        String curDrgYear = indicatorCalculateDto.getLastFiveYears().get(0);
        String lastDrgYear = indicatorCalculateDto.getLastFiveYears().get(1);
        List<DepartmentIndicatorEntity> curYearDrgData = lastFiveYearsDrgData.stream().filter(e -> e.getTime().equals(curDrgYear)).collect(Collectors.toList());
        List<DepartmentIndicatorEntity> lastYearDrgData = lastFiveYearsDrgData.stream().filter(e -> e.getTime().equals(lastDrgYear)).collect(Collectors.toList());
        Map<String, List<DepartmentIndicatorEntity>> curYearDrgMap = curYearDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> lastYearDrgMap = lastYearDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));


        //   查询同类科室
        List<DepartmentDto> departments = departmentIndicatorMapper.getDepartments(indicatorCalculateDto);
        indicatorCalculateDto.setDepartmentDtoList(departments);

        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));
        List<DepartmentIndicatorEntity> allDeptCurDayData = indicatorCalculateMapper.queryEscalationGroupByDept(indicatorCalculateDto); //天表数据

        //查询前端给的时间的近三年时间数据
        Map<String, String> currentDeptValue = new HashMap<>();
        Map<String, String> lastDeptValue = new HashMap<>();
        Map<String, String> beforeDeptValue = new HashMap<>();
        Map<String, String> previousDeptValue = new HashMap<>();

        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));
        List<DepartmentIndicatorEntity> curDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            currentDeptValue = curDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        indicatorCalculateDto.setStartTime(yoyTimes.get(0));
        indicatorCalculateDto.setEndTime(yoyTimes.get(yoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> lastDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            lastDeptValue = lastDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        indicatorCalculateDto.setStartTime(beforeYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(beforeYoyTimes.get(beforeYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> beforeDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            beforeDeptValue = beforeDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        indicatorCalculateDto.setStartTime(previousYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(previousYoyTimes.get(previousYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> previousDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            previousDeptValue = previousDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }


        //查出当前科室近五年数据
        indicatorCalculateDto.setElementIds(null);
        Year currentYear = Year.now();//今年
        indicatorCalculateDto.setQueryYear(currentYear.toString());
        List<DepartmentIndicatorEntity> curYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        indicatorCalculateDto.setQueryYear(currentYear.minusYears(1).toString());
        List<DepartmentIndicatorEntity> lastYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        indicatorCalculateDto.setQueryYear(currentYear.minusYears(2).toString());
        List<DepartmentIndicatorEntity> beforeYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        indicatorCalculateDto.setQueryYear(currentYear.minusYears(3).toString());
        List<DepartmentIndicatorEntity> previousYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        indicatorCalculateDto.setQueryYear(currentYear.minusYears(4).toString());
        List<DepartmentIndicatorEntity> endYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        Map<String, String> currentMapValue = new HashMap<>();
        Map<String, String> lastMapValue = new HashMap<>();
        Map<String, String> beforeMapValue = new HashMap<>();
        Map<String, String> previousMapValue = new HashMap<>();
        Map<String, String> endMapValue = new HashMap<>();

        if (curYearData != null) {
            currentMapValue = curYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        if (lastYearData != null) {
            lastMapValue = lastYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        if (beforeYearData != null) {
            beforeMapValue = beforeYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        if (previousYearData != null) {
            previousMapValue = previousYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        if (endYearData != null) {
            endMapValue = endYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        //根据科室进行分组
        Map<String, List<DepartmentIndicatorEntity>> curMapValue = allDeptCurDayData.stream().collect(Collectors.groupingBy(e -> e.getDeptName()));
        for (IndicatorOverviewDto indicatorOverviewDto : deptIndicatorList) {

            DataListDto dataListDto = new DataListDto();
            DataDetail dataDetail = new DataDetail();
            dataListDto.setIndicatorName(indicatorOverviewDto.getIndicatorName());
            dataListDto.setDataDetails(dataDetail);

            String formula = indicatorOverviewDto.getCalculationFormulaId();
            String dx = indicatorOverviewDto.getDx();//指标导向
            BigDecimal fullValue = indicatorOverviewDto.getFullValue();


            Map<String, BigDecimal> valueMap = new HashMap<>();
            // 计算出每个科室的指标值 然后进行排序
            for (DepartmentDto departmentDto : departments) {

                List<DepartmentIndicatorEntity> curList = curMapValue.get(departmentDto.getDepartmentName());

                String indexValue = "0";
                //解析当前指标的公式，通过元素值计算指标值
                if (curList != null) {
                    Map<String, String> mapValue = curList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                    indexValue = Calculator.conversionToSting(formula, mapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
                    if (indexValue.equals("-")) {
                        indexValue = "0";
                    }
                }
                valueMap.put(departmentDto.getDepartmentName(), new BigDecimal(indexValue));
            }

            //将每个科室及每个科室的值进行排序
            List<Map.Entry<String, BigDecimal>> list = new ArrayList<>(valueMap.entrySet());

            double zbdx = Double.valueOf(dx);
            if (zbdx == 0 || zbdx == 1) {
                Collections.sort(list, new Comparator<Map.Entry<String, BigDecimal>>() {
                    @Override
                    public int compare(Map.Entry<String, BigDecimal> o1, Map.Entry<String, BigDecimal> o2) {
                        return o2.getValue().compareTo(o1.getValue());
                    }
                });
            } else {
                Collections.sort(list, new Comparator<Map.Entry<String, BigDecimal>>() {
                    @Override
                    public int compare(Map.Entry<String, BigDecimal> o1, Map.Entry<String, BigDecimal> o2) {
                        return o1.getValue().compareTo(o2.getValue());
                    }
                });
            }

            // 创建一个Map来存储每个key的排序号
            Map<String, Integer> rankMap = new LinkedHashMap<>();
            int sort = 1;
            for (Map.Entry<String, BigDecimal> entry : list) {
                rankMap.put(entry.getKey(), sort++);
            }
            //设置排名
            dataListDto.setRank(rankMap.get(indicatorCalculateDto.getUserInfo().getWardName()));

            //近五年指标值
            String curYearValue = "0";
            String lastYearValue = "0";
            String beforeYearValue = "0";
            String previousYearValue = "0";
            String endYearValue = "0";

            //近五年分子值
            String numerator = "0";
            String lastNumerator = "0";
            String beforeNumerator = "0";
            String previousNumerator = "0";
            String endNumerator = "0";

            //近五年分母值
            String denominator = "0";
            String lastDenominator = "0";
            String beforeDenominator = "0";
            String previousDenominator = "0";
            String endDenominator = "0";

            // 求出近五年数据
            curYearValue = Calculator.conversionToSting(formula, currentMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            lastYearValue = Calculator.conversionToSting(formula, lastMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            beforeYearValue = Calculator.conversionToSting(formula, beforeMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            previousYearValue = Calculator.conversionToSting(formula, previousMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            endYearValue = Calculator.conversionToSting(formula, endMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值

            //取出分子、分母的计算公式
            String[] item = indicatorOverviewDto.getCalculationFormulaId().split("/");
            String fzFormula = item[0];
            String fmFormula = item[1];

            //近五年分子值
            numerator = Calculator.conversionToSting(fzFormula, currentMapValue);
            lastNumerator = Calculator.conversionToSting(fzFormula, lastMapValue);
            beforeNumerator = Calculator.conversionToSting(fzFormula, beforeMapValue);
            previousNumerator = Calculator.conversionToSting(fzFormula, previousMapValue);
            endNumerator = Calculator.conversionToSting(fzFormula, endMapValue);
            //近五年分母值
            denominator = Calculator.conversionToSting(fmFormula, currentMapValue);
            lastDenominator = Calculator.conversionToSting(fmFormula, lastMapValue);
            beforeDenominator = Calculator.conversionToSting(fmFormula, beforeMapValue);
            previousDenominator = Calculator.conversionToSting(fmFormula, previousMapValue);
            endDenominator = Calculator.conversionToSting(fmFormula, endMapValue);


            OverDataDto dataDto = new OverDataDto();
            OverDataDto lastDataDto = new OverDataDto();
            OverDataDto beforeDataDto = new OverDataDto();
            OverDataDto previousDataDto = new OverDataDto();
            OverDataDto endDataDto = new OverDataDto();

            //分母值
            dataDto.setDenominator(denominator);
            lastDataDto.setDenominator(lastDenominator);
            beforeDataDto.setDenominator(beforeDenominator);
            previousDataDto.setDenominator(previousDenominator);
            endDataDto.setDenominator(endDenominator);

            //满分值
            dataDto.setFullValue(indicatorOverviewDto.getFullValue().toString());
            lastDataDto.setFullValue(indicatorOverviewDto.getFullValue().toString());
            beforeDataDto.setFullValue(indicatorOverviewDto.getFullValue().toString());
            previousDataDto.setFullValue(indicatorOverviewDto.getFullValue().toString());
            endDataDto.setFullValue(indicatorOverviewDto.getFullValue().toString());

            //指标
            dataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            lastDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            beforeDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            previousDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            endDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());

            //指标值
            dataDto.setIndicatorValue(curYearValue);
            lastDataDto.setIndicatorValue(lastYearValue);
            beforeDataDto.setIndicatorValue(beforeYearValue);
            previousDataDto.setIndicatorValue(previousYearValue);
            endDataDto.setIndicatorValue(endYearValue);

            //分子值
            dataDto.setNumerator(numerator);
            lastDataDto.setNumerator(lastNumerator);
            beforeDataDto.setNumerator(beforeNumerator);
            previousDataDto.setNumerator(previousNumerator);
            endDataDto.setNumerator(endNumerator);

            //时间
            dataDto.setTime(currentYear.toString());
            lastDataDto.setTime(currentYear.minusYears(1).toString());
            beforeDataDto.setTime(currentYear.minusYears(2).toString());
            previousDataDto.setTime(currentYear.minusYears(3).toString());
            endDataDto.setTime(currentYear.minusYears(4).toString());

            //单位
            dataDto.setUnit(indicatorOverviewDto.getUnit());
            lastDataDto.setUnit(indicatorOverviewDto.getUnit());
            beforeDataDto.setUnit(indicatorOverviewDto.getUnit());
            previousDataDto.setUnit(indicatorOverviewDto.getUnit());
            endDataDto.setUnit(indicatorOverviewDto.getUnit());

            //同比
            dataDto.setYoyValue(calculateGrowthRate(curYearValue, lastYearValue));
            lastDataDto.setYoyValue(calculateGrowthRate(lastYearValue, beforeYearValue));
            beforeDataDto.setYoyValue(calculateGrowthRate(beforeYearValue, previousYearValue));
            previousDataDto.setYoyValue(calculateGrowthRate(previousYearValue, endYearValue));
            endDataDto.setYoyValue("-");

            //国考数据
            dataDto.setGKValue("-");
            lastDataDto.setGKValue("-");
            beforeDataDto.setGKValue("-");
            previousDataDto.setGKValue("-");
            endDataDto.setGKValue("-");


            dataListDto.getDataDetails().getDeptList1().add(dataDto);
            dataListDto.getDataDetails().getDeptList1().add(lastDataDto);
            dataListDto.getDataDetails().getDeptList1().add(beforeDataDto);
            dataListDto.getDataDetails().getDeptList1().add(previousDataDto);
            dataListDto.getDataDetails().getDeptList1().add(endDataDto);


            AnnexDataDto annexDataDto = new AnnexDataDto();
            annexDataDto.setDeptName(indicatorCalculateDto.getUserInfo().getWardName());

            List<AnnexYearDto> annexYearDtoList = new ArrayList<>();
            AnnexYearDto curAnnexYearDto = new AnnexYearDto();
            AnnexYearDto lastAnnexYearDto = new AnnexYearDto();
            AnnexYearDto beforeAnnexYearDto = new AnnexYearDto();
            annexYearDtoList.add(curAnnexYearDto);
            annexYearDtoList.add(lastAnnexYearDto);
            annexYearDtoList.add(beforeAnnexYearDto);
            annexDataDto.setAnnexYearDtos(annexYearDtoList);

            //时间
            curAnnexYearDto.setTime(times.get(0) + "~" + times.get(times.size() - 1));
            lastAnnexYearDto.setTime(yoyTimes.get(0) + "~" + yoyTimes.get(yoyTimes.size() - 1));
            beforeAnnexYearDto.setTime(beforeYoyTimes.get(0) + "~" + beforeYoyTimes.get(beforeYoyTimes.size() - 1));

            //满分值
            curAnnexYearDto.setFullValue(fullValue);
            lastAnnexYearDto.setFullValue(fullValue);
            beforeAnnexYearDto.setFullValue(fullValue);

            //指标值
            // 求出近三年数据
            String indexValue = Calculator.conversionToSting(formula, currentDeptValue);
            String lastValue = Calculator.conversionToSting(formula, lastDeptValue);
            String beforeValue = Calculator.conversionToSting(formula, beforeDeptValue);
            String previousValue = Calculator.conversionToSting(formula, previousDeptValue);


            curAnnexYearDto.setIndicatorValue(indexValue == "-" ? new BigDecimal("0") : new BigDecimal(indexValue));
            lastAnnexYearDto.setIndicatorValue(lastValue == "-" ? new BigDecimal("0") : new BigDecimal(lastValue));
            beforeAnnexYearDto.setIndicatorValue(beforeValue == "-" ? new BigDecimal("0") : new BigDecimal(beforeValue));

            //计算同比增幅
            String yoyGrowValue = calculateGrowthRate(indexValue, lastValue);
            String lastGrowValue = calculateGrowthRate(lastValue, beforeValue);
            String beforeGrowValue = calculateGrowthRate(beforeValue, previousValue);


            curAnnexYearDto.setYoyValue(yoyGrowValue == "-" ? new BigDecimal("0") : new BigDecimal(yoyGrowValue));
            lastAnnexYearDto.setYoyValue(lastGrowValue == "-" ? new BigDecimal("0") : new BigDecimal(lastGrowValue));
            beforeAnnexYearDto.setYoyValue(beforeGrowValue == "-" ? new BigDecimal("0") : new BigDecimal(beforeGrowValue));

            dataListDto.getDataDetails().getDeptList2().add(annexDataDto);


            // 取出当前指标及其子指标 根据父指标的index_code 子指标以父指标为开头的
            List<IndicatorDataEntity> filteredIndicators = relationIndicators.stream()
                    .filter(e -> e.getIndexCode().startsWith(indicatorOverviewDto.getIndexCode()))
                    .collect(Collectors.toList());

            List<DrgDataDto> drgDataDtoList = new ArrayList<>();
            for (IndicatorDataEntity filteredIndicator : filteredIndicators) {
                DrgDataDto drgDataDto = new DrgDataDto();
                String drgFormula = filteredIndicator.getCalculationFormulaId();
                String drgValue = Calculator.conversionToSting(drgFormula, currentDeptValue);

                Map<String, String> drgInfoMap = new LinkedHashMap<>();
                // 下面遍历填充医疗组数据
                for (Map.Entry<String, List<DepartmentIndicatorEntity>> entry : curDrgMap.entrySet()) {
                    String drgName = entry.getKey();
                    List<DepartmentIndicatorEntity> drgIndicatorEntityList = entry.getValue();
                    Map<String, String> drgMapValue = drgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                    String singleDrgValue = Calculator.conversionToSting(drgFormula, drgMapValue);
                    drgInfoMap.put(drgName, singleDrgValue);
                }

                //指标名称
                drgDataDto.setIndicatorName(filteredIndicator.getIndexCode() + filteredIndicator.getIndexName());
                //指标单位
                drgDataDto.setIndicatorUnit(filteredIndicator.getIndexUnit());
                //科室数据
                drgDataDto.setIndicatorValue(drgValue);
                drgDataDto.setDrgInfoMap(drgInfoMap);
                drgDataDtoList.add(drgDataDto);

            }
            dataListDto.getDataDetails().setDrgDataDtoList(drgDataDtoList);

            List<DrgOverDataDto> drgOverDataDtoList = new ArrayList<>();
            for (Map.Entry<String, List<DepartmentIndicatorEntity>> entry : curYearDrgMap.entrySet()) {
                String drgName = entry.getKey();
                List<DepartmentIndicatorEntity> curDrgIndicatorEntityList = entry.getValue();
                List<DepartmentIndicatorEntity> lastDrgIndicatorEntityList = lastYearDrgMap.get(drgName);//获取去年同一诊疗组的数据


                Map<String, String> curDrgMapValue = curDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                Map<String, String> lastDrgMapValue = new HashMap<>();
                if (lastDrgIndicatorEntityList != null) {
                    lastDrgMapValue = lastDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }

                String curDrgValue = Calculator.conversionToSting(formula, curDrgMapValue);//今年指标值
                String lastDrgValue = Calculator.conversionToSting(formula, lastDrgMapValue);//去年指标值
                String yoyDrgValue = calculateGrowthRate(curDrgValue, lastDrgValue);

                String drgNumerator = Calculator.conversionToSting(fzFormula, curDrgMapValue);//分子值
                String drgDenominator = Calculator.conversionToSting(fmFormula, curDrgMapValue);//分母值

                DrgOverDataDto drgOverDataDto = new DrgOverDataDto();
                drgOverDataDto.setTime(curDrgYear + "年");
                drgOverDataDto.setDoctorName(drgName);
                drgOverDataDto.setNumerator(drgNumerator);
                drgOverDataDto.setDenominator(drgDenominator);
                drgOverDataDto.setIndicatorValue(curDrgValue);
                drgOverDataDto.setGKValue("-");
                drgOverDataDto.setFullValue(fullValue.toString());
                drgOverDataDto.setYoyValue(yoyDrgValue);
                drgOverDataDtoList.add(drgOverDataDto);
            }
            dataListDto.getDataDetails().setDrgOverDataDtoList(drgOverDataDtoList);


            // 计算诊疗组当前选择的时间及同期两年的时间数据
            List<DrgYoyDto> drgYoyDtoList = new ArrayList<>();

            for (Map.Entry<String, List<DepartmentIndicatorEntity>> entry : curDrgMap.entrySet()) {

                //今年
                String drgName = entry.getKey();
                List<DepartmentIndicatorEntity> curDrgIndicatorEntityList = entry.getValue();
                Map<String, String> curDrgMapValue = curDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                String curDrgValue = Calculator.conversionToSting(formula, curDrgMapValue);

                //去年同期
                List<DepartmentIndicatorEntity> lastDrgIndicatorEntityList = lastDrgMap.get(drgName);
                Map<String, String> lastDrgMapValue = new HashMap<>();
                if (lastDrgIndicatorEntityList != null) {
                    lastDrgMapValue = lastDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }
                String lastDrgValue = Calculator.conversionToSting(formula, lastDrgMapValue);

                //前年同期
                List<DepartmentIndicatorEntity> beforeDrgIndicatorEntityList = beforeDrgMap.get(drgName);
                Map<String, String> beforeDrgMapValue = new HashMap<>();
                if (beforeDrgIndicatorEntityList != null) {
                    beforeDrgMapValue = beforeDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }
                String beforeDrgValue = Calculator.conversionToSting(formula, beforeDrgMapValue);

                //大前年同期
                List<DepartmentIndicatorEntity> previousDrgIndicatorEntityList = previousDrgMap.get(drgName);
                Map<String, String> previousDrgMapValue = new HashMap<>();
                if (previousDrgIndicatorEntityList != null) {
                    previousDrgMapValue = previousDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }
                String previousDrgValue = Calculator.conversionToSting(formula, previousDrgMapValue);

                //计算同比
                String curDrgYoyValue=calculateGrowthRate(curDrgValue,lastDrgValue);
                String lastDrgYoyValue=calculateGrowthRate(lastDrgValue,beforeDrgValue);
                String beforeDrgYoyValue=calculateGrowthRate(beforeDrgValue,previousDrgValue);


                //当前医生的近几年同期数据对象
                DrgYoyInfo drgCurInfo = new DrgYoyInfo();
                DrgYoyInfo drgLastInfo = new DrgYoyInfo();
                DrgYoyInfo drgBeforeInfo = new DrgYoyInfo();

                //近几年同期数据对象赋值
                drgCurInfo.setIndicatorValue(curDrgValue);
                drgCurInfo.setTime(times.get(0) + "~" + times.get(times.size() - 1));
                drgCurInfo.setFullValue(fullValue.toString());
                drgCurInfo.setYoyValue(curDrgYoyValue);

                drgLastInfo.setIndicatorValue(lastDrgValue);
                drgLastInfo.setTime(yoyTimes.get(0) + "~" + yoyTimes.get(yoyTimes.size() - 1));
                drgLastInfo.setFullValue(fullValue.toString());
                drgLastInfo.setYoyValue(lastDrgYoyValue);

                drgBeforeInfo.setIndicatorValue(beforeDrgValue);
                drgBeforeInfo.setTime(beforeYoyTimes.get(0) + "~" + beforeYoyTimes.get(beforeYoyTimes.size() - 1));
                drgBeforeInfo.setFullValue(fullValue.toString());
                drgBeforeInfo.setYoyValue(beforeDrgYoyValue);



                //设置诊疗组医生名称
                DrgYoyDto drgYoyDto = new DrgYoyDto();
                drgYoyDto.setDoctorName(drgName);

                //添加当前医生的近几年同期数据
                drgYoyDto.getDrgYoyInfoList().add(drgCurInfo);
                drgYoyDto.getDrgYoyInfoList().add(drgLastInfo);
                drgYoyDto.getDrgYoyInfoList().add(drgBeforeInfo);

                drgYoyDtoList.add(drgYoyDto);
            }
            dataListDto.getDataDetails().setDrgYoyDtoList(drgYoyDtoList);


            dataListDtoList.add(dataListDto);

        }
        return dataListDtoList;
    }

    public List<DataListDto> getCommonIndicatorDataList(IndicatorCalculateDto indicatorCalculateDto) {

        List<DataListDto> dataListDtoList = new ArrayList<>();
        List<String> times = indicatorCalculateDto.getTimes();
        if (times.size() == 0) {
            return null;
        }
        List<String> yoyTimes = getYoyTime(times);
        List<String> beforeYoyTimes = getYoyTime(yoyTimes);
        List<String> previousYoyTimes = getYoyTime(beforeYoyTimes);

        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));

        Map<String, List<IndicatorOverviewDto>> overviewData = indicatorCalculateService.getCommonIndicatorOverviewData(indicatorCalculateDto);
        //flag   0:满分  1:进步  其它:退步
        String key = indicatorCalculateDto.getFlag() == 0 ? "full" : indicatorCalculateDto.getFlag() == 1 ? "up" : "down";
        if (CollectionUtils.isEmpty(overviewData.get(key))) {
            return null;
        }
        // 查出所有手填指标的 id
        List<ElementDataEntity> elementDataEntities = indicatorCalculateMapper.getDeptElement();
        //将id全部抽取出来
        List<String> handFillIds = elementDataEntities.stream().map(e -> e.getId()).collect(Collectors.toList());

        List<IndicatorOverviewDto> deptIndicatorList = new ArrayList<>();
        // 确定当前指标是否是科室层面的指标  只有科室层面的指标才有必要查科室数据
        List<IndicatorOverviewDto> indicatorOverviewDtos = overviewData.get(key);

        for (IndicatorOverviewDto indicatorOverviewDto : indicatorOverviewDtos) {
            if (org.springframework.util.StringUtils.isEmpty(indicatorOverviewDto.getIds())) {
                continue;
            }
            String[] ids = indicatorOverviewDto.getIds().split(",");
            List<String> idList = Arrays.asList(ids);
            if (handFillIds.containsAll(idList)) {
                //说明是科室指标
                deptIndicatorList.add(indicatorOverviewDto);
            }
        }

        //  以下部分用来查询诊疗组信息
        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));

        // 根据所有父指标的index_code拿到其对应所有子指标
        List<String> indexCodeList = indicatorOverviewDtos.stream().map(e -> e.getIndexCode()).collect(Collectors.toList());
        indicatorCalculateDto.setIndexCodeList(indexCodeList);
        List<IndicatorDataEntity> relationIndicators = departmentIndicatorMapper.getRelationIndicators(indicatorCalculateDto);


        // 查出前端给的时间段及同几期每个诊疗组的数据
        List<DepartmentIndicatorEntity> curDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);

        indicatorCalculateDto.setStartTime(yoyTimes.get(0));
        indicatorCalculateDto.setEndTime(yoyTimes.get(yoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> lastDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);

        indicatorCalculateDto.setStartTime(beforeYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(beforeYoyTimes.get(beforeYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> beforeDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);

        indicatorCalculateDto.setStartTime(previousYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(previousYoyTimes.get(previousYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> previousDrgData = indicatorCalculateMapper.queryEscalationGroupByDrg(indicatorCalculateDto);


        Map<String, List<DepartmentIndicatorEntity>> curDrgMap = curDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> lastDrgMap = lastDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> beforeDrgMap = beforeDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> previousDrgMap = previousDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));


        // 查询当前科室近五年诊疗组信息
        setLastFiveYears(indicatorCalculateDto);
        List<DepartmentIndicatorEntity> lastFiveYearsDrgData = indicatorCalculateMapper.queryLastFiveYearsDrgData(indicatorCalculateDto);
        // 暂时只展示近一年的数据，因为今年的数据涉及到同比值，所以只取近两年的数据
        String curDrgYear = indicatorCalculateDto.getLastFiveYears().get(0);
        String lastDrgYear = indicatorCalculateDto.getLastFiveYears().get(1);
        List<DepartmentIndicatorEntity> curYearDrgData = lastFiveYearsDrgData.stream().filter(e -> e.getTime().equals(curDrgYear)).collect(Collectors.toList());
        List<DepartmentIndicatorEntity> lastYearDrgData = lastFiveYearsDrgData.stream().filter(e -> e.getTime().equals(lastDrgYear)).collect(Collectors.toList());
        Map<String, List<DepartmentIndicatorEntity>> curYearDrgMap = curYearDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));
        Map<String, List<DepartmentIndicatorEntity>> lastYearDrgMap = lastYearDrgData.stream().filter(e -> e.getGroupName() != null).collect(Collectors.groupingBy(e -> e.getGroupName()));

        //   查询同类科室
        List<DepartmentDto> departments = departmentIndicatorMapper.getDepartments(indicatorCalculateDto);
        indicatorCalculateDto.setDepartmentDtoList(departments);


        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));
        List<DepartmentIndicatorEntity> allDeptCurDayData = indicatorCalculateMapper.queryEscalationGroupByDept(indicatorCalculateDto); //天表数据

        //查询前端给的时间的近三年时间数据
        Map<String, String> currentDeptValue = new HashMap<>();
        Map<String, String> lastDeptValue = new HashMap<>();
        Map<String, String> beforeDeptValue = new HashMap<>();
        Map<String, String> previousDeptValue = new HashMap<>();

        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size() - 1));
        List<DepartmentIndicatorEntity> curDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            currentDeptValue = curDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        indicatorCalculateDto.setStartTime(yoyTimes.get(0));
        indicatorCalculateDto.setEndTime(yoyTimes.get(yoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> lastDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            lastDeptValue = lastDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        indicatorCalculateDto.setStartTime(beforeYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(beforeYoyTimes.get(beforeYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> beforeDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            beforeDeptValue = beforeDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        indicatorCalculateDto.setStartTime(previousYoyTimes.get(0));
        indicatorCalculateDto.setEndTime(previousYoyTimes.get(previousYoyTimes.size() - 1));
        List<DepartmentIndicatorEntity> previousDeptData = indicatorCalculateMapper.queryEscalationGroupBySingleDept(indicatorCalculateDto);
        if (curDeptData != null) {
            previousDeptValue = previousDeptData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }


        //查出近五年数据
        indicatorCalculateDto.setElementIds(null);
        Year currentYear = Year.now();//今年
        indicatorCalculateDto.setQueryYear(currentYear.toString());
        List<DepartmentIndicatorEntity> curYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        indicatorCalculateDto.setQueryYear(currentYear.minusYears(1).toString());
        List<DepartmentIndicatorEntity> lastYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        indicatorCalculateDto.setQueryYear(currentYear.minusYears(2).toString());
        List<DepartmentIndicatorEntity> beforeYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        indicatorCalculateDto.setQueryYear(currentYear.minusYears(3).toString());
        List<DepartmentIndicatorEntity> previousYearData = indicatorCalculateMapper.queryEscalationGroupByYear(indicatorCalculateDto);

        Map<String, String> currentMapValue = new HashMap<>();
        Map<String, String> lastMapValue = new HashMap<>();
        Map<String, String> beforeMapValue = new HashMap<>();
        Map<String, String> previousMapValue = new HashMap<>();
        Map<String, String> endMapValue = new HashMap<>();

        if (curYearData != null) {
            currentMapValue = curYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        if (lastYearData != null) {
            lastMapValue = lastYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        if (beforeYearData != null) {
            beforeMapValue = beforeYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        if (previousYearData != null) {
            previousMapValue = previousYearData.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
        }

        //根据科室进行分组
        Map<String, List<DepartmentIndicatorEntity>> curMapValue = allDeptCurDayData.stream().collect(Collectors.groupingBy(e -> e.getDeptName()));
        for (IndicatorOverviewDto indicatorOverviewDto : deptIndicatorList) {

            DataListDto dataListDto = new DataListDto();
            DataDetail dataDetail = new DataDetail();
            dataListDto.setIndicatorName(indicatorOverviewDto.getIndicatorName());
            dataListDto.setDataDetails(dataDetail);


            String formula = indicatorOverviewDto.getCalculationFormulaId();
            String dx = indicatorOverviewDto.getDx();//指标导向
            BigDecimal fullValue = indicatorOverviewDto.getFullValue();

            Map<String, BigDecimal> valueMap = new HashMap<>();
            // 计算出每个科室的指标值 然后进行排序
            for (DepartmentDto departmentDto : departments) {

                List<DepartmentIndicatorEntity> curList = curMapValue.get(departmentDto.getDepartmentName());

                String indexValue = "0";
                //解析当前指标的公式，通过元素值计算指标值
                if (curList != null) {
                    Map<String, String> mapValue = curList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                    indexValue = Calculator.conversionToSting(formula, mapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
                    if (indexValue.equals("-")) {
                        indexValue = "0";
                    }
                }
                valueMap.put(departmentDto.getDepartmentName(), new BigDecimal(indexValue));
            }

            //将每个科室及每个科室的值进行排序
            List<Map.Entry<String, BigDecimal>> list = new ArrayList<>(valueMap.entrySet());

            double zbdx = Double.valueOf(dx);
            if (zbdx == 0 || zbdx == 1) {
                Collections.sort(list, new Comparator<Map.Entry<String, BigDecimal>>() {
                    @Override
                    public int compare(Map.Entry<String, BigDecimal> o1, Map.Entry<String, BigDecimal> o2) {
                        return o2.getValue().compareTo(o1.getValue());
                    }
                });
            } else {
                Collections.sort(list, new Comparator<Map.Entry<String, BigDecimal>>() {
                    @Override
                    public int compare(Map.Entry<String, BigDecimal> o1, Map.Entry<String, BigDecimal> o2) {
                        return o1.getValue().compareTo(o2.getValue());
                    }
                });
            }

            // 创建一个Map来存储每个key的排序号
            Map<String, Integer> rankMap = new LinkedHashMap<>();
            int sort = 1;
            for (Map.Entry<String, BigDecimal> entry : list) {
                rankMap.put(entry.getKey(), sort++);
            }
            //设置排名
            dataListDto.setRank(rankMap.get(indicatorCalculateDto.getUserInfo().getWardName()));

            //近五年指标值
            String curYearValue = "0";
            String lastYearValue = "0";
            String beforeYearValue = "0";
            String previousYearValue = "0";
            String endYearValue = "0";

            //近五年分子值
            String numerator = "0";
            String lastNumerator = "0";
            String beforeNumerator = "0";
            String previousNumerator = "0";
            String endNumerator = "0";

            //近五年分母值
            String denominator = "0";
            String lastDenominator = "0";
            String beforeDenominator = "0";
            String previousDenominator = "0";
            String endDenominator = "0";

            // 求出近五年数据
            curYearValue = Calculator.conversionToSting(formula, currentMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            lastYearValue = Calculator.conversionToSting(formula, lastMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            beforeYearValue = Calculator.conversionToSting(formula, beforeMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            previousYearValue = Calculator.conversionToSting(formula, previousMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值
            endYearValue = Calculator.conversionToSting(formula, endMapValue);//当前指标值,如果当前指标涉及到多个元素计算，那么结果就是多元素数据计算的值，如果不涉及，就是其本身的值

            //取出分子、分母的计算公式
            String[] item = indicatorOverviewDto.getCalculationFormulaId().split("/");
            String fzFormula = item[0];
            String fmFormula = item[1];

            //近五年分子值
            numerator = Calculator.conversionToSting(fzFormula, currentMapValue);
            lastNumerator = Calculator.conversionToSting(fzFormula, lastMapValue);
            beforeNumerator = Calculator.conversionToSting(fzFormula, beforeMapValue);
            previousNumerator = Calculator.conversionToSting(fzFormula, previousMapValue);
            endNumerator = Calculator.conversionToSting(fzFormula, endMapValue);
            //近五年分母值
            denominator = Calculator.conversionToSting(fmFormula, currentMapValue);
            lastDenominator = Calculator.conversionToSting(fmFormula, lastMapValue);
            beforeDenominator = Calculator.conversionToSting(fmFormula, beforeMapValue);
            previousDenominator = Calculator.conversionToSting(fmFormula, previousMapValue);
            endDenominator = Calculator.conversionToSting(fmFormula, endMapValue);


            OverDataDto dataDto = new OverDataDto();
            OverDataDto lastDataDto = new OverDataDto();
            OverDataDto beforeDataDto = new OverDataDto();
            OverDataDto previousDataDto = new OverDataDto();
            OverDataDto endDataDto = new OverDataDto();

            //分母值
            dataDto.setDenominator(denominator);
            lastDataDto.setDenominator(lastDenominator);
            beforeDataDto.setDenominator(beforeDenominator);
            previousDataDto.setDenominator(previousDenominator);
            endDataDto.setDenominator(endDenominator);

            //满分值
            dataDto.setFullValue("-");
            lastDataDto.setFullValue("-");
            beforeDataDto.setFullValue("-");
            previousDataDto.setFullValue("-");
            endDataDto.setFullValue("-");

            //指标
            dataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            lastDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            beforeDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            previousDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());
            endDataDto.setIndicator(indicatorOverviewDto.getIndicatorName());

            //指标值
            dataDto.setIndicatorValue(curYearValue);
            lastDataDto.setIndicatorValue(lastYearValue);
            beforeDataDto.setIndicatorValue(beforeYearValue);
            previousDataDto.setIndicatorValue(previousYearValue);
            endDataDto.setIndicatorValue(endYearValue);

            //分子值
            dataDto.setNumerator(numerator);
            lastDataDto.setNumerator(lastNumerator);
            beforeDataDto.setNumerator(beforeNumerator);
            previousDataDto.setNumerator(previousNumerator);
            endDataDto.setNumerator(endNumerator);

            //时间
            dataDto.setTime(currentYear.toString());
            lastDataDto.setTime(currentYear.minusYears(1).toString());
            beforeDataDto.setTime(currentYear.minusYears(2).toString());
            previousDataDto.setTime(currentYear.minusYears(3).toString());
            endDataDto.setTime(currentYear.minusYears(4).toString());

            //单位
            dataDto.setUnit(indicatorOverviewDto.getUnit());
            lastDataDto.setUnit(indicatorOverviewDto.getUnit());
            beforeDataDto.setUnit(indicatorOverviewDto.getUnit());
            previousDataDto.setUnit(indicatorOverviewDto.getUnit());
            endDataDto.setUnit(indicatorOverviewDto.getUnit());

            //同比
            dataDto.setYoyValue(calculateGrowthRate(curYearValue, lastYearValue));
            lastDataDto.setYoyValue(calculateGrowthRate(lastYearValue, beforeYearValue));
            beforeDataDto.setYoyValue(calculateGrowthRate(beforeYearValue, previousYearValue));
            previousDataDto.setYoyValue(calculateGrowthRate(previousYearValue, endYearValue));
            endDataDto.setYoyValue("-");

            //国考数据
            dataDto.setGKValue("-");
            lastDataDto.setGKValue("-");
            beforeDataDto.setGKValue("-");
            previousDataDto.setGKValue("-");
            endDataDto.setGKValue("-");


            dataListDto.getDataDetails().getDeptList1().add(dataDto);
            dataListDto.getDataDetails().getDeptList1().add(lastDataDto);
            dataListDto.getDataDetails().getDeptList1().add(beforeDataDto);
            dataListDto.getDataDetails().getDeptList1().add(previousDataDto);
            dataListDto.getDataDetails().getDeptList1().add(endDataDto);


            AnnexDataDto annexDataDto = new AnnexDataDto();
            annexDataDto.setDeptName(indicatorCalculateDto.getUserInfo().getWardName());

            List<AnnexYearDto> annexYearDtoList = new ArrayList<>();
            AnnexYearDto curAnnexYearDto = new AnnexYearDto();
            AnnexYearDto lastAnnexYearDto = new AnnexYearDto();
            AnnexYearDto beforeAnnexYearDto = new AnnexYearDto();
            annexYearDtoList.add(curAnnexYearDto);
            annexYearDtoList.add(lastAnnexYearDto);
            annexYearDtoList.add(beforeAnnexYearDto);
            annexDataDto.setAnnexYearDtos(annexYearDtoList);

            //时间
            curAnnexYearDto.setTime(times.get(0) + "~" + times.get(times.size() - 1));
            lastAnnexYearDto.setTime(yoyTimes.get(0) + "~" + yoyTimes.get(yoyTimes.size() - 1));
            beforeAnnexYearDto.setTime(beforeYoyTimes.get(0) + "~" + beforeYoyTimes.get(beforeYoyTimes.size() - 1));

            //满分值
            curAnnexYearDto.setFullValue(fullValue);
            lastAnnexYearDto.setFullValue(fullValue);
            beforeAnnexYearDto.setFullValue(fullValue);

            //指标值
            // 求出近三年数据
            String indexValue = Calculator.conversionToSting(formula, currentDeptValue);
            String lastValue = Calculator.conversionToSting(formula, lastDeptValue);
            String beforeValue = Calculator.conversionToSting(formula, beforeDeptValue);
            String previousValue = Calculator.conversionToSting(formula, previousDeptValue);


            curAnnexYearDto.setIndicatorValue(indexValue == "-" ? new BigDecimal("0") : new BigDecimal(indexValue));
            lastAnnexYearDto.setIndicatorValue(lastValue == "-" ? new BigDecimal("0") : new BigDecimal(lastValue));
            beforeAnnexYearDto.setIndicatorValue(beforeValue == "-" ? new BigDecimal("0") : new BigDecimal(beforeValue));

            //计算同比增幅
            String yoyGrowValue = calculateGrowthRate(indexValue, lastValue);
            String lastGrowValue = calculateGrowthRate(lastValue, beforeValue);
            String beforeGrowValue = calculateGrowthRate(beforeValue, previousValue);


            curAnnexYearDto.setYoyValue(yoyGrowValue == "-" ? new BigDecimal("0") : new BigDecimal(yoyGrowValue));
            lastAnnexYearDto.setYoyValue(lastGrowValue == "-" ? new BigDecimal("0") : new BigDecimal(lastGrowValue));
            beforeAnnexYearDto.setYoyValue(beforeGrowValue == "-" ? new BigDecimal("0") : new BigDecimal(beforeGrowValue));

            dataListDto.getDataDetails().getDeptList2().add(annexDataDto);

            // 取出当前指标及其子指标 根据父指标的index_code 子指标以父指标为开头的
            List<IndicatorDataEntity> filteredIndicators = relationIndicators.stream()
                    .filter(e -> e.getIndexCode().startsWith(indicatorOverviewDto.getIndexCode()))
                    .collect(Collectors.toList());
            List<DrgDataDto> drgDataDtoList = new ArrayList<>();
            for (IndicatorDataEntity filteredIndicator : filteredIndicators) {
                DrgDataDto drgDataDto = new DrgDataDto();
                String drgFormula = filteredIndicator.getCalculationFormulaId();
                String drgValue = Calculator.conversionToSting(drgFormula, currentDeptValue);

                Map<String, String> drgInfoMap = new LinkedHashMap<>();
                // 下面遍历填充医疗组数据
                for (Map.Entry<String, List<DepartmentIndicatorEntity>> entry : curDrgMap.entrySet()) {
                    String drgName = entry.getKey();
                    List<DepartmentIndicatorEntity> drgIndicatorEntityList = entry.getValue();
                    Map<String, String> drgMapValue = drgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                    String singleDrgValue = Calculator.conversionToSting(drgFormula, drgMapValue);
                    drgInfoMap.put(drgName, singleDrgValue);
                }

                //指标名称
                drgDataDto.setIndicatorName(filteredIndicator.getIndexCode() + filteredIndicator.getIndexName());
                //指标单位
                drgDataDto.setIndicatorUnit(filteredIndicator.getIndexUnit());
                //科室数据
                drgDataDto.setIndicatorValue(drgValue);
                drgDataDto.setDrgInfoMap(drgInfoMap);
                drgDataDtoList.add(drgDataDto);

            }
            dataListDto.getDataDetails().setDrgDataDtoList(drgDataDtoList);

            // 计算诊疗组历年数据
            List<DrgOverDataDto> drgOverDataDtoList = new ArrayList<>();
            for (Map.Entry<String, List<DepartmentIndicatorEntity>> entry : curYearDrgMap.entrySet()) {
                String drgName = entry.getKey();
                List<DepartmentIndicatorEntity> curDrgIndicatorEntityList = entry.getValue();
                List<DepartmentIndicatorEntity> lastDrgIndicatorEntityList = lastYearDrgMap.get(drgName);//获取去年同一诊疗组的数据


                Map<String, String> curDrgMapValue = curDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                Map<String, String> lastDrgMapValue = new HashMap<>();
                if (lastDrgIndicatorEntityList != null) {
                    lastDrgMapValue = lastDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }

                String curDrgValue = Calculator.conversionToSting(formula, curDrgMapValue);//今年指标值
                String lastDrgValue = Calculator.conversionToSting(formula, lastDrgMapValue);//去年指标值
                String yoyDrgValue = calculateGrowthRate(curDrgValue, lastDrgValue);

                String drgNumerator = Calculator.conversionToSting(fzFormula, curDrgMapValue);//分子值
                String drgDenominator = Calculator.conversionToSting(fmFormula, curDrgMapValue);//分母值

                DrgOverDataDto drgOverDataDto = new DrgOverDataDto();
                drgOverDataDto.setTime(curDrgYear + "年");
                drgOverDataDto.setDoctorName(drgName);
                drgOverDataDto.setNumerator(drgNumerator);
                drgOverDataDto.setDenominator(drgDenominator);
                drgOverDataDto.setIndicatorValue(curDrgValue);
                drgOverDataDto.setGKValue("-");
                drgOverDataDto.setFullValue("-");
                drgOverDataDto.setYoyValue(yoyDrgValue);
                drgOverDataDtoList.add(drgOverDataDto);
            }
            dataListDto.getDataDetails().setDrgOverDataDtoList(drgOverDataDtoList);

            List<DrgYoyDto> drgYoyDtoList = new ArrayList<>();

            for (Map.Entry<String, List<DepartmentIndicatorEntity>> entry : curDrgMap.entrySet()) {

                //今年
                String drgName = entry.getKey();
                List<DepartmentIndicatorEntity> curDrgIndicatorEntityList = entry.getValue();
                Map<String, String> curDrgMapValue = curDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                String curDrgValue = Calculator.conversionToSting(formula, curDrgMapValue);

                //去年同期
                List<DepartmentIndicatorEntity> lastDrgIndicatorEntityList = lastDrgMap.get(drgName);
                Map<String, String> lastDrgMapValue = new HashMap<>();
                if (lastDrgIndicatorEntityList != null) {
                    lastDrgMapValue = lastDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }
                String lastDrgValue = Calculator.conversionToSting(formula, lastDrgMapValue);

                //前年同期
                List<DepartmentIndicatorEntity> beforeDrgIndicatorEntityList = beforeDrgMap.get(drgName);
                Map<String, String> beforeDrgMapValue = new HashMap<>();
                if (beforeDrgIndicatorEntityList != null) {
                    beforeDrgMapValue = beforeDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }
                String beforeDrgValue = Calculator.conversionToSting(formula, beforeDrgMapValue);

                //大前年同期
                List<DepartmentIndicatorEntity> previousDrgIndicatorEntityList = previousDrgMap.get(drgName);
                Map<String, String> previousDrgMapValue = new HashMap<>();
                if (previousDrgIndicatorEntityList != null) {
                    previousDrgMapValue = previousDrgIndicatorEntityList.stream().collect(Collectors.toMap(e -> "${" + e.getId() + "}", e -> e.getElementNumber()));
                }
                String previousDrgValue = Calculator.conversionToSting(formula, previousDrgMapValue);

                //计算同比
                String curDrgYoyValue=calculateGrowthRate(curDrgValue,lastDrgValue);
                String lastDrgYoyValue=calculateGrowthRate(lastDrgValue,beforeDrgValue);
                String beforeDrgYoyValue=calculateGrowthRate(beforeDrgValue,previousDrgValue);


                //当前医生的近几年同期数据对象
                DrgYoyInfo drgCurInfo = new DrgYoyInfo();
                DrgYoyInfo drgLastInfo = new DrgYoyInfo();
                DrgYoyInfo drgBeforeInfo = new DrgYoyInfo();

                //近几年同期数据对象赋值
                drgCurInfo.setIndicatorValue(curDrgValue);
                drgCurInfo.setTime(times.get(0) + "~" + times.get(times.size() - 1));
                drgCurInfo.setYoyValue(curDrgYoyValue);
                drgCurInfo.setFullValue("-");

                drgLastInfo.setIndicatorValue(lastDrgValue);
                drgLastInfo.setTime(yoyTimes.get(0) + "~" + yoyTimes.get(yoyTimes.size() - 1));
                drgLastInfo.setYoyValue(lastDrgYoyValue);
                drgLastInfo.setFullValue("-");


                drgBeforeInfo.setIndicatorValue(beforeDrgValue);
                drgBeforeInfo.setTime(beforeYoyTimes.get(0) + "~" + beforeYoyTimes.get(beforeYoyTimes.size() - 1));
                drgBeforeInfo.setYoyValue(beforeDrgYoyValue);
                drgBeforeInfo.setFullValue("-");


                //设置诊疗组医生名称
                DrgYoyDto drgYoyDto = new DrgYoyDto();
                drgYoyDto.setDoctorName(drgName);

                //添加当前医生的近几年同期数据
                drgYoyDto.getDrgYoyInfoList().add(drgCurInfo);
                drgYoyDto.getDrgYoyInfoList().add(drgLastInfo);
                drgYoyDto.getDrgYoyInfoList().add(drgBeforeInfo);

                drgYoyDtoList.add(drgYoyDto);
            }
            dataListDto.getDataDetails().setDrgYoyDtoList(drgYoyDtoList);

            dataListDtoList.add(dataListDto);

        }
        return dataListDtoList;
    }

    /**
     * 计算同比时间
     *
     * @param
     * @param
     * @return
     */
    public List<String> getYoyTime(List<String> times) {
        List<String> lastYearDates = new ArrayList<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        boolean isWholeMonth;
        // 使用流式操作按年份和月份分组,分组后的map中 键是年和月，如2024-01， 值是List集合，存的是相同年月的字符串,同时指定插入顺序，采用LinkedHashMap
        Map<String, List<String>> groupedDates = times.stream().collect(Collectors.groupingBy(date -> date.substring(0, 7), LinkedHashMap::new, Collectors.toList()));
        for (Map.Entry<String, List<String>> entry : groupedDates.entrySet()) {
            List<String> groupTimes = entry.getValue();
            // 判断是否是一整个月
            isWholeMonth = isWholeMonth(groupTimes);
            for (String currentDate : groupTimes) {
                LocalDate date = LocalDate.parse(currentDate, formatter);
                if (isWholeMonth) {
                    int lastYearMonthLength = date.minusYears(1).lengthOfMonth(); // 获取去年同月的天数
                    LocalDate lastYearStartDate = LocalDate.of(date.getYear() - 1, date.getMonth(), 1); // 去年同月的第一天
                    for (int i = 0; i < lastYearMonthLength; i++) {
                        lastYearDates.add(lastYearStartDate.plusDays(i).format(formatter));
                    }
                    break;
                } else {
                    LocalDate lastYearDate = date.minusYears(1);
                    lastYearDates.add(lastYearDate.format(formatter));
                }
            }
        }


        return lastYearDates;
    }

    public String calculateGrowthRate(String currentValue, String previousValue) {
        if (currentValue.equals("-") || previousValue.equals("-")) {
            return "-"; // 当值为 "-" 时，无法计算增长率，直接返回 "-"
        }

        double current = Double.parseDouble(currentValue);
        double previous = Double.parseDouble(previousValue);

        if (previous == 0.0) {
            return "0"; // 当前值为非零而上一期值为零时,直接返回0，无意义
        }

        double growthRate = (current - previous) / previous;
        return String.format("%.2f", growthRate); // 将增长率转换为字符串，并返回,保留两位小数，四舍五入
    }

    //判断当前时间数组是否为一整个月
    private static boolean isWholeMonth(List<String> times) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate firstDate = LocalDate.parse(times.get(0), formatter);
        LocalDate lastDate = LocalDate.parse(times.get(times.size() - 1), formatter);
        if (firstDate.getDayOfMonth() != 1) {
            return false;
        }
        int daysInMonth = firstDate.lengthOfMonth();
        return lastDate.getDayOfMonth() == daysInMonth;
    }

    public List<DrgGroupDataDto> getDrgGroupDataList(IndicatorCalculateDto indicatorCalculateDto) {
        List<String> times=indicatorCalculateDto.getTimes();
        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size()-1));
        List<DrgGroupDataDto> drgGroupDataDtoList=indicatorCalculateMapper.getDrgGroupDataList(indicatorCalculateDto);
        List<DrgGroupDataDto> result= drgGroupDataDtoList.stream().filter(e->e.getDrgGroupName()!=null).collect(Collectors.toList());
        return result;
    }

    public List<PatientsInOutDto> getPatientsInOutHospitalList(IndicatorCalculateDto indicatorCalculateDto) {
        List<String> times=indicatorCalculateDto.getTimes();
        indicatorCalculateDto.setStartTime(times.get(0));
        indicatorCalculateDto.setEndTime(times.get(times.size()-1));
        List<PatientsInOutDto> patientsInOutDtoList=indicatorCalculateMapper.getPatientsInOutHospitalList(indicatorCalculateDto);
        return patientsInOutDtoList;
    }
}
